/**
 * Created by z30 on 15-6-5.
 */


var log4js          = require('log4js');
//var type            = require('../servertype.json');
var ev              = require('../conf/envv.js');

if (ev.ftype=='test' || ev.ftype=='dev')
{
    log4js.configure({
        appenders: [
            {
                type: "console"
                //category: "console" //注释掉就控制台输出
            },
            {
                type: "file",
                filename: './logs/idea.log',
                alwaysIncludePattern: true,
                pattern: "_yyyy-MM-dd",
                backups: 10,
                category: 'idea'
            }//日期文件格式
        ],
        replaceConsole: true   //替换console.log
    });
} else
{
    log4js.configure({
        appenders: [
            {
                type: "console",
                category: "console" //注释掉就控制台输出
            },
            {
                type: "file",
                filename: './logs/idea.log',
                alwaysIncludePattern: true,
                pattern: "_yyyy-MM-dd",
                backups: 10,
                category: 'idea'
            }//日期文件格式
        ],
        replaceConsole: true   //替换console.log
    });
}

var dateFileLog = log4js.getLogger('idea');
exports.logger = dateFileLog;
exports.use = function(app) {
    //页面请求日志,用auto的话,默认级别是WARN
    //app.use(log4js.connectLogger(dateFileLog, {level:'auto', format:':method :url'}));
    app.use(log4js.connectLogger(dateFileLog, {
        format:':remote-addr :method :url :status :response-time'+'ms'}));
};